<?php

namespace app\modules\v1\controllers;
use Yii;
use app\models\Api;
class ApiController extends BaseController
{
    public $modelClass = 'app\models\Shop';
    /**
     * @return array
     *  商品分类查询
     */
    public function actionTypes(){
        $api = new Api();
        $type_arr = $api->types();
        return $type_arr;
    }
    /**
     * @return array
     *  根据分类的id 查询商品
     *  $type_id 为搜索的条件id，根据类型的id值进行查询相对应的数据
     */
    public function actionShops(){
        $type_id = isset($_GET['type_id'])?$_GET['type_id']:1;
        $api = new Api();
        $data = $api->shops($type_id);
        return $data;
    }
    /**
     * @return array
     * 根据id 查询 商品详情信息
     */
    public  function actionShop_info(){
        $shop_id = isset($_GET['id'])?$_GET['id']:1;
        $api = new Api();
        $dataOne = $api->shopOne($shop_id);
        return $dataOne;
    }
    /**
     * @return array|bool
     *  将 商品存入到购物车中
     */
    public function actionShopcar(){
        $shop_id = isset($_GET['id'])?$_GET['id']:'';
        if($shop_id==''){
            return array('code'=>500,'msg'=>'您没有搜索条件，所以无法进行搜索');
        }
        $api = new Api();
        $shopCar = $api->AddShopCar($shop_id);
        return $shopCar;
    }
    /**
     * @return mixed
     *  ids 为 购物车中，所有物品的id值
     *
     */
    public function actionShoppay(){
        $ids = $_GET['ids'];
        $api = new Api();
        $payCar = $api->payCar($ids);
        return $payCar;
    }
    /**
     *  添加收货地址
     */
    public function actionAddtel(){
        $data = Yii::$app->request->get();
        $Api = new Api();
        $addRess = $Api->addRess($data);
        return $addRess;
    }




}